//
//  BaseViewController.m
//  CarOfHome2
//
//  Created by dlios on 15/9/23.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "BaseViewController.h"
#import <AFNetworking.h>

@interface BaseViewController ()



@end

@implementation BaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    self.Net = 1;
    // 1.获得网络监控的管理者
    AFNetworkReachabilityManager *mgr = [AFNetworkReachabilityManager sharedManager];
    // 2.设置网络状态改变后的处理
    [mgr setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        // 当网络状态改变了, 就会调用这个block
        switch (status) {
            case AFNetworkReachabilityStatusUnknown: // 未知网络
            {
                NSLog(@"未知网络");
                if (!self.Net) {
                    UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"网络已连接，请继续使用" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
                    [alert show];
                    self.view.userInteractionEnabled = YES;
                    self.Net = 1;
                }
                break;
            }
                
            case AFNetworkReachabilityStatusNotReachable: // 没有网络(断网)
            {
                NSLog(@"没有网络(断网)");
                UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"网络错误, 请检查网络" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
                [alert show];
                self.view.userInteractionEnabled = NO;
                self.Net = 0;
                break;
            }
            case AFNetworkReachabilityStatusReachableViaWWAN: // 手机自带网络
            {
                NSLog(@"手机自带网络");
                if (!self.Net) {
                    UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"网络已连接，请继续使用" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
                    [alert show];
                    self.view.userInteractionEnabled = YES;
                    self.Net = 1;
                }
                break;
            }
            case AFNetworkReachabilityStatusReachableViaWiFi: // WIFI
            {
                NSLog(@"WIFI");
                if (!self.Net) {
                    UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"网络已连接，请继续使用" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
                    [alert show];
                    self.view.userInteractionEnabled = YES;
                    self.Net = 1;
                }
                
                break;
            }
        }
    }];
    // 3.开始监控
    [mgr startMonitoring];



}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
